<template>
  <div class="commentItem">
    <div class="infoBox">
      <img :src="item.author.avatar" alt="" @click="$emit('reComment', item)" />
      <div class="nameBox">
        <span class="name">{{ item.author.nickname }}</span>
        <span class="time">{{ item.created_at | formatTime }}</span>
      </div>
      <div class="zanBox" @click="star">
        <span :class="{ actived: starComments.includes(item.id) }">{{
          item.star
        }}</span>
        <i
          class="iconfont icon-icon_dianzanliang"
          :class="{ actived: starComments.includes(item.id) }"
        ></i>
      </div>
    </div>
    <!-- 评论内容 -->
    <div class="contentBox">
      <div class="content">{{ item.content }}</div>
      <div class="replyBox" v-if="item.children_comments.length > 0">
        <div
          class="reply"
          v-for="(items, indexs) in item.children_comments"
          :key="indexs"
        >
          <span class="name">{{ items.author }}:</span>
          <span>{{ items.content }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { starArticleComment } from '@/api/api.js'
import { mapGetters, mapMutations } from 'vuex'
export default {
  props: ['item'],
  computed: {
    ...mapGetters(['starComments'])
  },
  methods: {
    ...mapMutations(['SETSTARARTICLECOMMENTS']),
    async star () {
      const res = await starArticleComment({ id: this.item.id })
      // console.log(res)
      this.SETSTARARTICLECOMMENTS(res.data.list)
      this.item.star = res.data.num
      this.$toast.success('点赞成功')
    }
  }
}
</script>

<style lang="less" scoped>
.commentItem {
  .infoBox {
    margin-top: 15px;
    display: flex;
    align-items: center;
    img {
      width: 35px;
      height: 35px;
      border-radius: 50%;
      margin-right: 9px;
    }
    .nameBox {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      flex: 1;
      .name {
        font-size: 12px;
        font-weight: 600;
        color: #545671;
      }
      .time {
        font-size: 12px;
        color: #b4b4bd;
      }
    }
    .zanBox {
      span {
        color: #b4b4bd;
        font-size: 12px;
      }
      .iconfont {
        color: #b4b4bd;
        font-size: 24px;
      }
    }
  }
  .contentBox {
    padding-left: 44px;
    .content {
      margin-top: 11px;
      font-size: 16px;
      color: #181a39;
      line-height: 27px;
    }
    .replyBox {
      margin-top: 5px;
      padding-left: 15px;
      padding-bottom: 12px;
      background: #f7f4f5;
      .reply {
        font-size: 14px;
        color: #545671;
        padding-top: 15px;
        .name {
          font-weight: 500;
          margin-right: 5px;
        }
      }
    }
  }
  span.actived {
    color: #e40137 !important;
  }
  i.actived {
    color: #e40137 !important;
  }
}
</style>
